package com.xuecheng.search.controller;

import com.xuecheng.commons.model.dto.CoursePubIndexDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author Sober_wxy
 * @date 2022/7/25 16:07
 */
@RestController
public class SearchController {
        @Autowired
        private SearchService searchService;

        /**
         * 课程搜索-- 分页 高亮 过条件滤
         * @param pageRequest 分页请求{pageNo,pageSize}
         * @param dto CoursePubIndexDto
         * @return page
         */
        @PostMapping("/course-search")
        public ResponseResult search(PageRequest pageRequest, @RequestBody CoursePubIndexDto dto) throws IOException {
                return searchService.search(pageRequest,dto);
        }

        /**
         * 根据id 在ES索引库查询课程发布数据
         * @param id 课程发布id
         * @return CoursePubIndexVo
         */
        @GetMapping("/course-search/{id}")
        public ResponseResult findById(@PathVariable("id") Long id) throws IOException {
                return searchService.findById(id);
        }
}
